package sr.codemg.exception;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import sr.codemg.utils.ResponseCode;
import sr.codemg.vm.Base;

/**
 * 函数未知错误结果流程时使用。
 */
@Getter
@Slf4j
public class RunException extends RuntimeException {
    Base.Response vm;

    public RunException() {
        super();
    }

    public RunException(Base.Response vm) {
        super(vm.getMsg());
        this.vm = vm;
        log.error("ReturnException ----> \n", "error code\n" + vm.getCode() + "---- error msg\n" + vm.getMsg());
    }

    public RunException(String code, String... msg) {
        super(code);
        this.vm = ResponseCode.getBase(code, msg);
        log.error("ReturnException ----> \n", "error code\n" + vm.getCode() + "---- error msg\n" + vm.getMsg());
    }

    public RunException(String code, String msg) {
        super(msg);
        this.vm = new Base.Response(code, msg);
        log.error("ReturnException ----> \n", "error code\n" + vm.getCode() + "---- error msg\n" + vm.getMsg());
    }

    public RunException(Exception e) {
        super(e);
        log.error("RunException ----> \n", "error code\n" + e.getMessage());
    }
}
